package com.alibaba.controller;

import com.alibaba.dubbo.OrderService;
import com.alibaba.dubbo.UserService;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.modle.common.ResponseEntity;
import com.alibaba.modle.order.Order;
import com.alibaba.modle.user.User;
import com.alibaba.user.service.UserServiceImpl;
import com.google.gson.JsonObject;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: TongRui乀
 * @Date: 2021/8/22 12:40
 * @description：
 */
@RequestMapping("user")
@RestController
public class UserController {


    @DubboReference
    OrderService orderService;

    @Autowired
    private UserService userService;

    @GetMapping("getUserOrderInfo")
    public ResponseEntity<JSONObject> getUserOrderInfo(Integer userId){

        ResponseEntity<User> userResponse = userService.getUserById(userId);

        var userInfo = userResponse.getData();

        var orderInfoRes = orderService.getOrderById(1L);

        Order orderInfo = orderInfoRes.getData();

        JSONObject res = new JSONObject();

        res.put("code", 200);
        res.put("userInfo", userInfo);
        res.put("orderInfo", orderInfo);

        return ResponseEntity.<JSONObject>builder().data(res).build();
    }

}
